package com.mm.mindmap.consistency;

import com.mm.common.utils.theadPoolUtil.BulkTask;
import com.mm.mindmap.consistency.strategy.scheme.IConsistencyScheme;


/**
 * @Program: 8.mindmap
 * @Author: 海里的鱼
 * @Create: 2024-08-28 09:30
 * @Name: 一致性任务
 * @Desc: 用来批量执行【DataFunc】数据
 */
public class ConsistencyTask extends BulkTask {
    //写入数据
    private ConsistencyData data;

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 构造方法
     * @Describe: TODO
     **/
     public ConsistencyTask(ConsistencyData data) {
        this.data = data;
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 执行【DataFunc】操作数据
     * @Describe: TODO
     **/
    @Override
    public boolean executeFunction() throws Exception{
        //获取方案，并根据方案处理数据
        IConsistencyScheme scheme = data.getScheme();
        boolean isSuccess = true;
        try {
            isSuccess =  scheme.executeScheme(data);
        } catch (Exception e) {
            throw new ConsistencyException("【"+data.getType().getMessage()+"】的一致性任务执行失败,因为："+e.getMessage());
        }
        if (!isSuccess) {
            throw new ConsistencyException("【"+data.getType().getMessage()+"】的一致性任务执行失败");
        }
        return isSuccess;
    }

    public ConsistencyData getData() {
        return data;
    }

    public void setData(ConsistencyData data) {
        this.data = data;
    }
}
